package com.dingqb.androidproject.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * Created by dingqb on 2018/5/15.
 */

public class FIleUtil {
    public static boolean writeToFile(File file, boolean append, String content, String charset) {
        BufferedWriter bos = null;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file, append);
            bos = new BufferedWriter(new OutputStreamWriter(fos, charset));
            bos.write(content);
            return true;
        } catch (Exception e) {
            return false;
        } finally {
            try {
                if (bos != null) {
                    bos.flush();
                    bos.close();
                }
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
